#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/9/6 11:11
# @File           : __init__
# @IDE            : PyCharm
# @desc           : 描述

from sqlalchemy.ext.asyncio import AsyncSession
from core.crud import DalBase
from . import models, schemas


class OrderDal(DalBase):

    def __init__(self, db: AsyncSession):
        super(OrderDal, self).__init__()
        self.db = db
        self.model = models.DCOrder
        self.schema = schemas.OrderSimpleOut

    async def create_data(self, data: schemas.Order, v_return_obj: bool = False):
        order = await self.get_data(order_no=data.order_no, v_return_none=True)
        if not order:
            order = await super().create_data(data, v_return_obj=True)
        return await self.out_dict(order, v_return_obj=v_return_obj)


class OrderProgressDal(DalBase):
    def __init__(self, db: AsyncSession):
        super(OrderProgressDal, self).__init__()
        self.db = db
        self.model = models.DCOderProgress
        self.schema = schemas.OrderProgressSimpleOut


class OrderContentDal(DalBase):
    def __init__(self, db: AsyncSession):
        super(OrderContentDal, self).__init__()
        self.db = db
        self.model = models.DCOrderContent
        self.schema = schemas.OrderContentSimpleOut